package cn.edu.zafu.bigdata.liuwenyi;

import java.util.Scanner;

// 自定义异常类
class InvalidScoreException extends Exception {
    public InvalidScoreException(String message) {
        super(message);
    }
}

public class ScoreValidationExample {

    // 定义分数验证方法
    public static void checkScore(int score) throws InvalidScoreException {
        if (score < 0 || score > 100) {
            throw new InvalidScoreException("分数无效，分数必须在0到100之间");
        }
        System.out.println("分数有效: " + score);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        try {
            System.out.print("请输入分数: ");
            int score = scanner.nextInt();
            checkScore(score);
        } catch (InvalidScoreException e) {
            // 捕获自定义异常并输出提示信息
            System.out.println("发生异常: " + e.getMessage());
        } catch (Exception e) {
            // 捕获其他异常，如非整数输入
            System.out.println("输入无效，请输入一个整数");
        } finally {
            scanner.close(); // 关闭 Scanner
        }
    }
}
